package com.fzu.normalservice.controller;


import com.fzu.commonutil.util.R;
import com.fzu.normalservice.param.ResourceParam;
import com.fzu.normalservice.service.ResourceService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyq
 * @since 2023-04-11
 */
@RestController
@RequestMapping("/resource")
@RequiredArgsConstructor
public class ResourceController {
    private final ResourceService resourceService;

    /**
     * 获取资源树形列表
     * @return
     */
    @GetMapping
    public R treeList() {
        return R.ok().data(resourceService.treeList());
    }


    /**
     * 获取指定角色资源列
     * @return
     */
    @GetMapping("/{id}")
    public R treeList(@PathVariable("id") Integer id) {
        return R.ok().data(resourceService.listByRoleId(id));
    }

    /**
     * 更新权限
     * @param param
     * @return
     */
    @PostMapping
    public R update(@RequestBody @Valid ResourceParam param) {
        resourceService.update(param);
        return R.ok();
    }

}

